2020-2021 Sunseeker Telemetry and Lighting System
rtc_c_ex1_calendarmode.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
64 //******************************************************************************
65 
66 #include "driverlib.h"
67 
68 volatile Calendar newTime;
69 
70 void main (void)
71 {
72  Calendar currentTime;
73 
74  WDT_A_hold(WDT_A_BASE);
75 
76  //Set P1.0 to output direction
77  GPIO_setAsOutputPin(
78  GPIO_PORT_P1,
79  GPIO_PIN0
80  );
81 
82  /*
83  * Disable the GPIO power-on default high-impedance mode to activate
84  * previously configured port settings
85  */
86  PMM_unlockLPM5();
87 
88  // Configure PJ.4 and PJ.5 as input pins for LFXIN and LFXOUT mode
89  GPIO_setAsPeripheralModuleFunctionInputPin(
90  GPIO_PORT_PJ,
91  GPIO_PIN4 | GPIO_PIN5,
92  GPIO_PRIMARY_MODULE_FUNCTION
93  );
94 
95  //Initialize LFXT1
96  CS_turnOnLFXT(
97  CS_LFXT_DRIVE_3
98  );
99 
100  //Setup Current Time for Calendar
101  currentTime.Seconds = 0x00;
102  currentTime.Minutes = 0x26;
103  currentTime.Hours = 0x13;
104  currentTime.DayOfWeek = 0x03;
105  currentTime.DayOfMonth = 0x20;
106  currentTime.Month = 0x07;
107  currentTime.Year = 0x2011;
108 
109  //Initialize Calendar Mode of RTC
110  /*
111  * Base Address of the RTC_A
112  * Pass in current time, intialized above
113  * Use BCD as Calendar Register Format
114  */
115  RTC_C_initCalendar(RTC_C_BASE,
116  &currentTime,
117  RTC_C_FORMAT_BCD);
118 
119  //Setup Calendar Alarm for 5:00pm on the 5th day of the week.
120  //Note: Does not specify day of the week.
121  RTC_C_configureCalendarAlarmParam param = {0};
122  param.minutesAlarm = 0x00;
123  param.hoursAlarm = 0x17;
124  param.dayOfWeekAlarm = RTC_C_ALARMCONDITION_OFF;
125  param.dayOfMonthAlarm = 0x05;
126  RTC_C_configureCalendarAlarm(RTC_C_BASE, &param);
127 
128  //Specify an interrupt to assert every minute
129  RTC_C_setCalendarEvent(RTC_C_BASE,
130  RTC_C_CALENDAREVENT_MINUTECHANGE);
131 
132  //Enable interrupt for RTC Ready Status, which asserts when the RTC
133  //Calendar registers are ready to read.
134  //Also, enable interrupts for the Calendar alarm and Calendar event.
135  RTC_C_enableInterrupt(RTC_C_BASE,
136  RTCRDYIE + RTCTEVIE + RTCAIE);
137  RTC_C_enableInterrupt(RTC_C_BASE,
138  RTCRDYIFG + RTCTEVIFG + RTCAIFG);
139 
140  //Start RTC Clock
141  RTC_C_startClock(RTC_C_BASE);
142 
143  //Enter LPM3 mode with interrupts enabled
144  __bis_SR_register(LPM3_bits + GIE);
145  __no_operation();
146 }
147 
148 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
149 #pragma vector=RTC_VECTOR
150 __interrupt
151 #elif defined(__GNUC__)
152 __attribute__((interrupt(RTC_VECTOR)))
153 #endif
154 void RTC_ISR (void)
155 {
156  switch (__even_in_range(RTCIV, 16)) {
157  case RTCIV_NONE: break; //No interrupts
158  case RTCIV_RTCOFIFG: break; //RTCOFIFG
159  case RTCIV_RTCRDYIFG: //RTCRDYIFG
160  //Toggle P1.0 every second
161  GPIO_toggleOutputOnPin(
162  GPIO_PORT_P1,
163  GPIO_PIN0);
164  break;
165  case RTCIV_RTCTEVIFG: //RTCEVIFG
166  //Interrupts every minute
167  __no_operation();
168 
169  //Read out New Time a Minute Later BREAKPOINT HERE
170  newTime = RTC_C_getCalendarTime(RTC_C_BASE);
171  break;
172  case RTCIV_RTCAIFG: //RTCAIFG
173  //Interrupts 5:00pm on 5th day of week
174  __no_operation();
175  break;
176  case RTCIV_RT0PSIFG: break; //RT0PSIFG
177  case RTCIV_RT1PSIFG: break; //RT1PSIFG
178 
179  default: break;
180  }
181 }
182 
void main(void)
void RTC_ISR(void)
volatile Calendar newTime
MPU_initThreeSegmentsParam param
__no_operation()